﻿@model WqUser
@{
    ViewData["Title"] = "用户详情页";
    var user = Model;
}

<div class="row">
    <form id="ajaxForm" enctype="multipart/form-data" class="form-horizontal">
        <input type="hidden" asp-for="Id" />
        <div class="container-fluid">
            <div class="row form-group">
                <label class="control-label col-md-2">昵称</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="NickName" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">用户名</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="UserName" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">手机号</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="PhoneNumber" />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">邮箱</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="Email" />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">用户权限</label>
                <div class="col-md-10">
                    @{
                        foreach (WqUserAuth auth in Enum.GetValues(typeof(WqUserAuth)))
                        {
                            <span>@auth.ToString()</span><input type="checkbox" class="i-checks" name="UserAuth" value="@auth.ToString()" @(user.UserAuth.HasFlag(auth) ? "checked" : string.Empty) />
                        }
                    }
                </div>
            </div>
            <div class="row form-group" title="勾选后用户将不能登录">
                <label class="control-label col-md-2">可以登录</label>
                <div class="col-md-10">
                    @{
                        if (user.IsAdmin)
                        {
                            <span class="form-control">超级管理员不能禁止登录</span>
                        }
                        else
                        {
                            <input class="i-checks" name="Enable" id="Enable" type="checkbox" value="true" @(user.Enable ? "checked" : "") />
                        }
                    }
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">账号类型</label>
                <div class="col-md-10">
                    <div class="form-control">
                        @{
                            foreach (SupportOpenIdTypes support in Enum.GetValues(typeof(SupportOpenIdTypes)))
                            {
                                if (user.LoginType.HasFlag(support))
                                {
                                    <span>@support.ToString()</span>
                                }
                            }
                        }
                    </div>
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">关联账户ID</label>
                <div class="col-md-10">
                    @{
                        var baiduOpenID = user.OpenIdBaidu <= 0 ? "" : user.OpenIdBaidu.ToString();
                    }
                    <input class="form-control" type="text" value="@($"{user.OpenIdQQ} {baiduOpenID} {user.OpenIdAli}")" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">是否超管</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" value="@(user.IsAdmin?"是":"N/A")" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">登录时间</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="LoginTime" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">创建时间</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="CreateTime" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">更新时间</label>
                <div class="col-md-10">
                    <input class="form-control" type="text" asp-for="LastUpdate" readonly />
                </div>
            </div>
            <div class="row form-group">
                <div class="col-md-6 col-md-offset-2">
                    <button type="button" class="btn btn-primary ladda-button btn-save">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">
        $(".btn-save").click(function () {
            if ($("input[name='UserAuth']:checked").length == 0) {
                utils.ShowError("请选择用户权限");
                return;
            }

            $("#ajaxForm").ajaxSubmit({
                type: 'post',
                url: '@Url.Action("UpdateUser")',
                data: {

                },  // data是作为额外提交的表单数据
                success: function (e) {
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.reload(true);
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.data);
                }
            });
        });
    </script>
}